package work.konbai.bmc.cms.service.impl;

import work.konbai.bmc.cms.dao.BillDao;
import work.konbai.bmc.cms.domain.BillDO;
import work.konbai.bmc.cms.service.BillService;
import work.konbai.bmc.common.constant.enums.ExpenseStateEnum;
import work.konbai.bmc.common.utils.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author KonBAI
 * @version 1.0
 * Create by 2020/03/20 14:41
 */
@Service
public class BillServiceImpl implements BillService {
	@Autowired
	private BillDao billMapper;

	@Override
	public BillDO get(Long id){
		return billMapper.get(id);
	}

	@Override
	public List<BillDO> list(Map<String, Object> map){
		return billMapper.list(map);
	}

	@Override
	public List<BillDO> listBill(BillDO bill){
		return billMapper.listBill(bill);
	}

	@Override
	public int count(Map<String, Object> map){
		return billMapper.count(map);
	}

	@Override
	public int save(BillDO bill){
		return billMapper.save(bill);
	}

	@Override
	public int update(BillDO bill) {
		if (ExpenseStateEnum.AGREE.getCode().equals(bill.getState()) || ExpenseStateEnum.REFUSE.getCode().equals(bill.getState())) {
			bill.setApprovalBy(ShiroUtils.getUserId());
			bill.setApprovalUser(ShiroUtils.getUser().getName());
			bill.setApprovalTime(new Date());
		}
		return billMapper.update(bill);
	}

	@Override
	public int remove(Long id){
		return billMapper.remove(id);
	}

	@Override
	public int batchRemove(Long[] ids){
		return billMapper.batchRemove(ids);
	}

}
